import {Component} from '@angular/core';
import {LoadingServer} from './common/loading/loading.server';
import {TestBrowser} from '../TestBrowser';
import {MOBIL_H5_URL} from './config/config';
@Component({
    selector: 'app-root',
    templateUrl: './app.component.html',
    styleUrls: ['./app.component.scss'],
    providers: []
})
export class AppComponent {
    isVisible: boolean;
    key: boolean;
    isOkLoading: boolean;


    constructor(public http: LoadingServer) {
        this.isVisible = false;
        this.isOkLoading = false;
        this.key = true;
        const browserParams = TestBrowser.BrowserType();
        // 判断PC浏览器类型s
        // @ts-ignore
        if (browserParams.platform === 'desktop') {
            if (browserParams.supporter === 'chrome' && browserParams.engine === 'webkit') {
                // 判断所在浏览器内核支持版本达到对网站样式的兼容处理
                if (parseInt(browserParams.supporterVs, 0) < 70) {
                    this.isVisible = true;
                    this.key = true;
                } else {
                    this.isVisible = false;
                    this.key = false;
                }
            } else if (browserParams.supporter === 'opera' && browserParams.engine === 'webkit') {
                this.isVisible = true;
                this.key = true;
            } else if (browserParams.system === 'macos' && browserParams.supporter === 'safari' && browserParams.engine === 'webkit') {
                this.isVisible = true;
                this.key = true;
            } else if (browserParams.supporter === 'firefox' && browserParams.engine === 'gecko') {
                this.isVisible = false;
                this.key = false;
            } else if (browserParams.supporter === 'chrome' && browserParams.shell === 'qq') {
                this.isVisible = false;
                this.key = false;
            } else if (browserParams.supporter === 'iexplore' && browserParams.engine === 'trident') {
                this.isVisible = true;
                // alert('该浏览器需点击地址栏右侧切换到极速模式');
                this.key = true;
            } else if (browserParams.shell === 'wechat') {
                this.isVisible = true;
                this.key = true;
            } else if (browserParams.shell === 'uc') {
                this.isVisible = true;
                this.key = true;
            } else if (browserParams.shell === '360') {
            } else if (browserParams.shell === '2345') {
                this.isVisible = true;
                this.key = true;
            }
            // return;
        } else if (browserParams.platform === 'mobile') {   //
            this.key = true;
            window.location.href = MOBIL_H5_URL;
            setTimeout(() => {
                this.isVisible = false;
            }, 2000);
        } else if (browserParams.system === 'android') {
            window.location.href = MOBIL_H5_URL;
            setTimeout(() => {
                this.isVisible = false;
            }, 2000);
        } else if (browserParams.system === 'ios') {
            window.location.href = MOBIL_H5_URL;
            setTimeout(() => {
                this.isVisible = false;
            }, 2000);
        }
    }

    /**
     * 点击跳转到当前浏览器官网
     * @param num：类别值
     */
    linkToFn(num: number) {
        switch (num) {
            case 1:
                window.location.href = 'https://www.google.cn/chrome/';
                break;
            case 2:
                window.location.href = 'http://www.firefox.com.cn/';
                break;
            case 3:
                window.location.href = 'http://browser.360.cn/';
                break;
            case 4:
                window.location.href = 'https://browser.qq.com/?adtag=SEM170314011';
                break;
            default:
                break;
        }
    }
}
